﻿using System;
using System.Collections.Generic;

namespace MySqlQueryToolkit
{
    public interface IExplainQueryReporter
    {
        IEnumerable<ExplainQueryResult> Report(string query);
    }

    public class ExplainQueryReporter : IExplainQueryReporter
    {
        private readonly IExplainQueryRepository _explainQueryRepository;

        public ExplainQueryReporter(IExplainQueryRepository explainQueryRepository)
        {
            _explainQueryRepository = explainQueryRepository;
        }

        public IEnumerable<ExplainQueryResult> Report(string query)
        {
            if (string.IsNullOrEmpty(query))
            {
                throw new ArgumentException();
            }

            query = string.Format("EXPLAIN {0}", query);

            return _explainQueryRepository.GetEntitiesFromDatabase(query);
        }
    }
}
